/**
 * MiscTests
 *
 * @author Chris Pratt
 *
 * 9/1/2006
 */
package com.anodyzed.onyx.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

import static org.junit.Assert.*;
import org.junit.Test;

public class MiscTests {

  /**
   * Test the isNumeric method
   */
  @Test public void testIsNumeric () {
    assertTrue(Misc.isNumeric("0"));
    assertTrue(Misc.isNumeric("1"));
    assertTrue(Misc.isNumeric("65535"));
    assertFalse(Misc.isNumeric("1534x"));
    assertFalse(Misc.isNumeric("this"));
  } //testIsNumeric

  /**
   * Test the isEmpty(String) method
   */
  @Test public void testIsStringEmpty () {
    assertTrue(Misc.isEmpty((String)null));
    assertTrue(Misc.isEmpty(""));
    assertTrue(Misc.isEmpty("   "));
    assertFalse(Misc.isEmpty("empty"));
  } //testIsStringEmpty

  /**
   * Test the isEmpty(T[]) method
   */
  @Test public void testIsArrayEmpty () {
    Object[] array = null;
    assertTrue(Misc.isEmpty(array));
    array = new Object[0];
    assertTrue(Misc.isEmpty(array));
    array = new Object[1];
    assertFalse(Misc.isEmpty(array));
  } //testIsArrayEmpty

  /**
   * Test the isEmpty(Collection<?>) method
   */
  @Test public void testIsCollectionEmpty () {
    Collection<Object> collection = null;
    assertTrue(Misc.isEmpty(collection));
    collection = new ArrayList<Object>();
    assertTrue(Misc.isEmpty(collection));
    collection.add(new Object());
    assertFalse(Misc.isEmpty(collection));
    collection = new HashSet<Object>();
    assertTrue(Misc.isEmpty(collection));
    collection.add(new Object());
    assertFalse(Misc.isEmpty(collection));
  } //testIsCollectionEmpty

  /**
   * Test the isEmpty(Map<?,?>) method
   */
  @Test public void testIsMapEmpty () {
    Map<String,Object> map = null;
    assertTrue(Misc.isEmpty(map));
    map = new HashMap<String,Object>();
    assertTrue(Misc.isEmpty(map));
    map.put("new",new Object());
    assertFalse(Misc.isEmpty(map));
  } //testIsMapEmpty

} //*MiscTests
